<?php


namespace app\zftapi\controller;


use app\BaseController;
use app\service\zftService;
use think\facade\Db;
use util\JwtUtils;

class Alipay extends BaseController
{

    //获取支付宝用户的user_id
    public function getUserId()
    {
        $api = new zftService();
        //获取当前用户支付宝ID
        $code = request()->get('auth_code');
        $oauthtoken = $api->xcxoauthToken($code);
        if(property_exists($oauthtoken,'sub_msg')){
            return json(['msg' => $oauthtoken->sub_msg,'code'=>"500"]);
        }

        $user_id = $oauthtoken->user_id;//user_id
        $arr["userid"]=$user_id;
        $token=JwtUtils::getToken($arr);
        return json(["code"=>0,'accessToken' => $token]);

    }
}